﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace TinyERP.Framework.Controls
{
    public class DialogDecorator : KryptonForm
    {
        private DialogDecorator()
        {
            InitializeComponent();
        }
        public DialogDecorator(IDialog dialogForm): base()
        {
            InitializeComponent();
            this.Text = dialogForm.GetHeaderText();
            this.Controls.Add(dialogForm as UserControl);
            this.AutoSize = true;
            this.AcceptButton = dialogForm.GetAcceptButton();
            this.CancelButton = dialogForm.GetCancelButton();
            this.ClientSize = ((UserControl)dialogForm).Size;
            this.KeyPreview = true;
            dialogForm.RegisterShortcuts();
            dialogForm.CloseDialog += new CloseDialogHandler(OnCloseDialog);
            this.KeyDown += new KeyEventHandler(OnKeyDown);
        }
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            ShortcutHandler.GetInstance().HandleEvent(e);
        }
        private void OnCloseDialog(Control control)
        {
            this.Close();
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // DialogDecorator
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(537, 350);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "DialogDecorator";
            this.Text = "DialogDecorator";
            this.ResumeLayout(false);

        }

        #endregion
    }
}
